package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.PageSchema;
import com.xjgzinfo.usdp.domain.FlowConfig;
import com.xjgzinfo.usdp.domain.AppClass;
import com.xjgzinfo.usdp.repository.PageSchemaRepository;
import com.xjgzinfo.usdp.service.PageSchemaService;
import com.xjgzinfo.usdp.service.dto.PageSchemaDTO;
import com.xjgzinfo.usdp.service.mapper.PageSchemaMapper;
import com.xjgzinfo.usdp.service.dto.PageSchemaCriteria;
import com.xjgzinfo.usdp.service.PageSchemaQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link PageSchemaResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class PageSchemaResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_PATH = "AAAAAAAAAA";
    private static final String UPDATED_PATH = "BBBBBBBBBB";

    private static final String DEFAULT_DATA = "AAAAAAAAAA";
    private static final String UPDATED_DATA = "BBBBBBBBBB";

    private static final String DEFAULT_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_TYPE = "BBBBBBBBBB";

    private static final String DEFAULT_URL = "AAAAAAAAAA";
    private static final String UPDATED_URL = "BBBBBBBBBB";

    @Autowired
    private PageSchemaRepository pageSchemaRepository;

    @Autowired
    private PageSchemaMapper pageSchemaMapper;

    @Autowired
    private PageSchemaService pageSchemaService;

    @Autowired
    private PageSchemaQueryService pageSchemaQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restPageSchemaMockMvc;

    private PageSchema pageSchema;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static PageSchema createEntity(EntityManager em) {
        PageSchema pageSchema = new PageSchema()
            .name(DEFAULT_NAME)
            .path(DEFAULT_PATH)
            .data(DEFAULT_DATA)
            .type(DEFAULT_TYPE)
            .url(DEFAULT_URL);
        return pageSchema;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static PageSchema createUpdatedEntity(EntityManager em) {
        PageSchema pageSchema = new PageSchema()
            .name(UPDATED_NAME)
            .path(UPDATED_PATH)
            .data(UPDATED_DATA)
            .type(UPDATED_TYPE)
            .url(UPDATED_URL);
        return pageSchema;
    }

    @BeforeEach
    public void initTest() {
        pageSchema = createEntity(em);
    }

    @Test
    @Transactional
    public void createPageSchema() throws Exception {
        int databaseSizeBeforeCreate = pageSchemaRepository.findAll().size();
        // Create the PageSchema
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(pageSchema);
        restPageSchemaMockMvc.perform(post("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isCreated());

        // Validate the PageSchema in the database
        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeCreate + 1);
        PageSchema testPageSchema = pageSchemaList.get(pageSchemaList.size() - 1);
        assertThat(testPageSchema.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testPageSchema.getPath()).isEqualTo(DEFAULT_PATH);
        assertThat(testPageSchema.getData()).isEqualTo(DEFAULT_DATA);
        assertThat(testPageSchema.getType()).isEqualTo(DEFAULT_TYPE);
        assertThat(testPageSchema.getUrl()).isEqualTo(DEFAULT_URL);
    }

    @Test
    @Transactional
    public void createPageSchemaWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = pageSchemaRepository.findAll().size();

        // Create the PageSchema with an existing ID
        pageSchema.setId(1L);
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(pageSchema);

        // An entity with an existing ID cannot be created, so this API call must fail
        restPageSchemaMockMvc.perform(post("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isBadRequest());

        // Validate the PageSchema in the database
        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = pageSchemaRepository.findAll().size();
        // set the field null
        pageSchema.setName(null);

        // Create the PageSchema, which fails.
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(pageSchema);


        restPageSchemaMockMvc.perform(post("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isBadRequest());

        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkPathIsRequired() throws Exception {
        int databaseSizeBeforeTest = pageSchemaRepository.findAll().size();
        // set the field null
        pageSchema.setPath(null);

        // Create the PageSchema, which fails.
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(pageSchema);


        restPageSchemaMockMvc.perform(post("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isBadRequest());

        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkTypeIsRequired() throws Exception {
        int databaseSizeBeforeTest = pageSchemaRepository.findAll().size();
        // set the field null
        pageSchema.setType(null);

        // Create the PageSchema, which fails.
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(pageSchema);


        restPageSchemaMockMvc.perform(post("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isBadRequest());

        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllPageSchemas() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList
        restPageSchemaMockMvc.perform(get("/api/page-schemas?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(pageSchema.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].path").value(hasItem(DEFAULT_PATH)))
            .andExpect(jsonPath("$.[*].data").value(hasItem(DEFAULT_DATA.toString())))
            .andExpect(jsonPath("$.[*].type").value(hasItem(DEFAULT_TYPE)))
            .andExpect(jsonPath("$.[*].url").value(hasItem(DEFAULT_URL)));
    }
    
    @Test
    @Transactional
    public void getPageSchema() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get the pageSchema
        restPageSchemaMockMvc.perform(get("/api/page-schemas/{id}", pageSchema.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(pageSchema.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.path").value(DEFAULT_PATH))
            .andExpect(jsonPath("$.data").value(DEFAULT_DATA.toString()))
            .andExpect(jsonPath("$.type").value(DEFAULT_TYPE))
            .andExpect(jsonPath("$.url").value(DEFAULT_URL));
    }


    @Test
    @Transactional
    public void getPageSchemasByIdFiltering() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        Long id = pageSchema.getId();

        defaultPageSchemaShouldBeFound("id.equals=" + id);
        defaultPageSchemaShouldNotBeFound("id.notEquals=" + id);

        defaultPageSchemaShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultPageSchemaShouldNotBeFound("id.greaterThan=" + id);

        defaultPageSchemaShouldBeFound("id.lessThanOrEqual=" + id);
        defaultPageSchemaShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllPageSchemasByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where name equals to DEFAULT_NAME
        defaultPageSchemaShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the pageSchemaList where name equals to UPDATED_NAME
        defaultPageSchemaShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where name not equals to DEFAULT_NAME
        defaultPageSchemaShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the pageSchemaList where name not equals to UPDATED_NAME
        defaultPageSchemaShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByNameIsInShouldWork() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where name in DEFAULT_NAME or UPDATED_NAME
        defaultPageSchemaShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the pageSchemaList where name equals to UPDATED_NAME
        defaultPageSchemaShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where name is not null
        defaultPageSchemaShouldBeFound("name.specified=true");

        // Get all the pageSchemaList where name is null
        defaultPageSchemaShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllPageSchemasByNameContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where name contains DEFAULT_NAME
        defaultPageSchemaShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the pageSchemaList where name contains UPDATED_NAME
        defaultPageSchemaShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByNameNotContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where name does not contain DEFAULT_NAME
        defaultPageSchemaShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the pageSchemaList where name does not contain UPDATED_NAME
        defaultPageSchemaShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllPageSchemasByPathIsEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where path equals to DEFAULT_PATH
        defaultPageSchemaShouldBeFound("path.equals=" + DEFAULT_PATH);

        // Get all the pageSchemaList where path equals to UPDATED_PATH
        defaultPageSchemaShouldNotBeFound("path.equals=" + UPDATED_PATH);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByPathIsNotEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where path not equals to DEFAULT_PATH
        defaultPageSchemaShouldNotBeFound("path.notEquals=" + DEFAULT_PATH);

        // Get all the pageSchemaList where path not equals to UPDATED_PATH
        defaultPageSchemaShouldBeFound("path.notEquals=" + UPDATED_PATH);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByPathIsInShouldWork() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where path in DEFAULT_PATH or UPDATED_PATH
        defaultPageSchemaShouldBeFound("path.in=" + DEFAULT_PATH + "," + UPDATED_PATH);

        // Get all the pageSchemaList where path equals to UPDATED_PATH
        defaultPageSchemaShouldNotBeFound("path.in=" + UPDATED_PATH);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByPathIsNullOrNotNull() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where path is not null
        defaultPageSchemaShouldBeFound("path.specified=true");

        // Get all the pageSchemaList where path is null
        defaultPageSchemaShouldNotBeFound("path.specified=false");
    }
                @Test
    @Transactional
    public void getAllPageSchemasByPathContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where path contains DEFAULT_PATH
        defaultPageSchemaShouldBeFound("path.contains=" + DEFAULT_PATH);

        // Get all the pageSchemaList where path contains UPDATED_PATH
        defaultPageSchemaShouldNotBeFound("path.contains=" + UPDATED_PATH);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByPathNotContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where path does not contain DEFAULT_PATH
        defaultPageSchemaShouldNotBeFound("path.doesNotContain=" + DEFAULT_PATH);

        // Get all the pageSchemaList where path does not contain UPDATED_PATH
        defaultPageSchemaShouldBeFound("path.doesNotContain=" + UPDATED_PATH);
    }


    @Test
    @Transactional
    public void getAllPageSchemasByTypeIsEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where type equals to DEFAULT_TYPE
        defaultPageSchemaShouldBeFound("type.equals=" + DEFAULT_TYPE);

        // Get all the pageSchemaList where type equals to UPDATED_TYPE
        defaultPageSchemaShouldNotBeFound("type.equals=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByTypeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where type not equals to DEFAULT_TYPE
        defaultPageSchemaShouldNotBeFound("type.notEquals=" + DEFAULT_TYPE);

        // Get all the pageSchemaList where type not equals to UPDATED_TYPE
        defaultPageSchemaShouldBeFound("type.notEquals=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByTypeIsInShouldWork() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where type in DEFAULT_TYPE or UPDATED_TYPE
        defaultPageSchemaShouldBeFound("type.in=" + DEFAULT_TYPE + "," + UPDATED_TYPE);

        // Get all the pageSchemaList where type equals to UPDATED_TYPE
        defaultPageSchemaShouldNotBeFound("type.in=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByTypeIsNullOrNotNull() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where type is not null
        defaultPageSchemaShouldBeFound("type.specified=true");

        // Get all the pageSchemaList where type is null
        defaultPageSchemaShouldNotBeFound("type.specified=false");
    }
                @Test
    @Transactional
    public void getAllPageSchemasByTypeContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where type contains DEFAULT_TYPE
        defaultPageSchemaShouldBeFound("type.contains=" + DEFAULT_TYPE);

        // Get all the pageSchemaList where type contains UPDATED_TYPE
        defaultPageSchemaShouldNotBeFound("type.contains=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByTypeNotContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where type does not contain DEFAULT_TYPE
        defaultPageSchemaShouldNotBeFound("type.doesNotContain=" + DEFAULT_TYPE);

        // Get all the pageSchemaList where type does not contain UPDATED_TYPE
        defaultPageSchemaShouldBeFound("type.doesNotContain=" + UPDATED_TYPE);
    }


    @Test
    @Transactional
    public void getAllPageSchemasByUrlIsEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where url equals to DEFAULT_URL
        defaultPageSchemaShouldBeFound("url.equals=" + DEFAULT_URL);

        // Get all the pageSchemaList where url equals to UPDATED_URL
        defaultPageSchemaShouldNotBeFound("url.equals=" + UPDATED_URL);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByUrlIsNotEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where url not equals to DEFAULT_URL
        defaultPageSchemaShouldNotBeFound("url.notEquals=" + DEFAULT_URL);

        // Get all the pageSchemaList where url not equals to UPDATED_URL
        defaultPageSchemaShouldBeFound("url.notEquals=" + UPDATED_URL);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByUrlIsInShouldWork() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where url in DEFAULT_URL or UPDATED_URL
        defaultPageSchemaShouldBeFound("url.in=" + DEFAULT_URL + "," + UPDATED_URL);

        // Get all the pageSchemaList where url equals to UPDATED_URL
        defaultPageSchemaShouldNotBeFound("url.in=" + UPDATED_URL);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByUrlIsNullOrNotNull() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where url is not null
        defaultPageSchemaShouldBeFound("url.specified=true");

        // Get all the pageSchemaList where url is null
        defaultPageSchemaShouldNotBeFound("url.specified=false");
    }
                @Test
    @Transactional
    public void getAllPageSchemasByUrlContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where url contains DEFAULT_URL
        defaultPageSchemaShouldBeFound("url.contains=" + DEFAULT_URL);

        // Get all the pageSchemaList where url contains UPDATED_URL
        defaultPageSchemaShouldNotBeFound("url.contains=" + UPDATED_URL);
    }

    @Test
    @Transactional
    public void getAllPageSchemasByUrlNotContainsSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        // Get all the pageSchemaList where url does not contain DEFAULT_URL
        defaultPageSchemaShouldNotBeFound("url.doesNotContain=" + DEFAULT_URL);

        // Get all the pageSchemaList where url does not contain UPDATED_URL
        defaultPageSchemaShouldBeFound("url.doesNotContain=" + UPDATED_URL);
    }


    @Test
    @Transactional
    public void getAllPageSchemasByFlowConfigIsEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);
        FlowConfig flowConfig = FlowConfigResourceIT.createEntity(em);
        em.persist(flowConfig);
        em.flush();
        pageSchema.addFlowConfig(flowConfig);
        pageSchemaRepository.saveAndFlush(pageSchema);
        Long flowConfigId = flowConfig.getId();

        // Get all the pageSchemaList where flowConfig equals to flowConfigId
        defaultPageSchemaShouldBeFound("flowConfigId.equals=" + flowConfigId);

        // Get all the pageSchemaList where flowConfig equals to flowConfigId + 1
        defaultPageSchemaShouldNotBeFound("flowConfigId.equals=" + (flowConfigId + 1));
    }


    @Test
    @Transactional
    public void getAllPageSchemasByAppClassIsEqualToSomething() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);
        AppClass appClass = AppClassResourceIT.createEntity(em);
        em.persist(appClass);
        em.flush();
        pageSchema.setAppClass(appClass);
        pageSchemaRepository.saveAndFlush(pageSchema);
        Long appClassId = appClass.getId();

        // Get all the pageSchemaList where appClass equals to appClassId
        defaultPageSchemaShouldBeFound("appClassId.equals=" + appClassId);

        // Get all the pageSchemaList where appClass equals to appClassId + 1
        defaultPageSchemaShouldNotBeFound("appClassId.equals=" + (appClassId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultPageSchemaShouldBeFound(String filter) throws Exception {
        restPageSchemaMockMvc.perform(get("/api/page-schemas?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(pageSchema.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].path").value(hasItem(DEFAULT_PATH)))
            .andExpect(jsonPath("$.[*].data").value(hasItem(DEFAULT_DATA.toString())))
            .andExpect(jsonPath("$.[*].type").value(hasItem(DEFAULT_TYPE)))
            .andExpect(jsonPath("$.[*].url").value(hasItem(DEFAULT_URL)));

        // Check, that the count call also returns 1
        restPageSchemaMockMvc.perform(get("/api/page-schemas/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultPageSchemaShouldNotBeFound(String filter) throws Exception {
        restPageSchemaMockMvc.perform(get("/api/page-schemas?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restPageSchemaMockMvc.perform(get("/api/page-schemas/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingPageSchema() throws Exception {
        // Get the pageSchema
        restPageSchemaMockMvc.perform(get("/api/page-schemas/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updatePageSchema() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        int databaseSizeBeforeUpdate = pageSchemaRepository.findAll().size();

        // Update the pageSchema
        PageSchema updatedPageSchema = pageSchemaRepository.findById(pageSchema.getId()).get();
        // Disconnect from session so that the updates on updatedPageSchema are not directly saved in db
        em.detach(updatedPageSchema);
        updatedPageSchema
            .name(UPDATED_NAME)
            .path(UPDATED_PATH)
            .data(UPDATED_DATA)
            .type(UPDATED_TYPE)
            .url(UPDATED_URL);
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(updatedPageSchema);

        restPageSchemaMockMvc.perform(put("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isOk());

        // Validate the PageSchema in the database
        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeUpdate);
        PageSchema testPageSchema = pageSchemaList.get(pageSchemaList.size() - 1);
        assertThat(testPageSchema.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testPageSchema.getPath()).isEqualTo(UPDATED_PATH);
        assertThat(testPageSchema.getData()).isEqualTo(UPDATED_DATA);
        assertThat(testPageSchema.getType()).isEqualTo(UPDATED_TYPE);
        assertThat(testPageSchema.getUrl()).isEqualTo(UPDATED_URL);
    }

    @Test
    @Transactional
    public void updateNonExistingPageSchema() throws Exception {
        int databaseSizeBeforeUpdate = pageSchemaRepository.findAll().size();

        // Create the PageSchema
        PageSchemaDTO pageSchemaDTO = pageSchemaMapper.toDto(pageSchema);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restPageSchemaMockMvc.perform(put("/api/page-schemas").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(pageSchemaDTO)))
            .andExpect(status().isBadRequest());

        // Validate the PageSchema in the database
        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deletePageSchema() throws Exception {
        // Initialize the database
        pageSchemaRepository.saveAndFlush(pageSchema);

        int databaseSizeBeforeDelete = pageSchemaRepository.findAll().size();

        // Delete the pageSchema
        restPageSchemaMockMvc.perform(delete("/api/page-schemas/{id}", pageSchema.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<PageSchema> pageSchemaList = pageSchemaRepository.findAll();
        assertThat(pageSchemaList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
